package com.spic.business.accident.exterevents.plan.controller;

import com.spic.business.accident.exterevents.plan.domain.AccidentExternalRectificationPlan;
import com.spic.business.accident.exterevents.plan.service.IAccidentExternalRectificationPlanService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 内部事件整改计划Controller
 *
 * @author spic
 * @date 2021-12-03
 */
@RestController
@RequestMapping("accident/plan")
public class AccidentExternalRectificationPlanController extends BaseController {
    @Autowired
    private IAccidentExternalRectificationPlanService accidentExternalRectificationPlanService;

    /**
     * 查询内部事件整改计划列表
     */
    @PreAuthorize(hasPermi = "business/accident:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(AccidentExternalRectificationPlan accidentExternalRectificationPlan) {
        startPage();
        List<AccidentExternalRectificationPlan> list = accidentExternalRectificationPlanService.selectAccidentExternalRectificationPlanList(accidentExternalRectificationPlan);
        return getDataTable(list);
    }

    /**
     * 导出内部事件整改计划列表
     */
    @PreAuthorize(hasPermi = "business/accident:plan:export")
    @Log(title = "内部事件整改计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccidentExternalRectificationPlan accidentExternalRectificationPlan) throws IOException {
        List<AccidentExternalRectificationPlan> list = accidentExternalRectificationPlanService.selectAccidentExternalRectificationPlanList(accidentExternalRectificationPlan);
        ExcelUtil<AccidentExternalRectificationPlan> util = new ExcelUtil<AccidentExternalRectificationPlan>(AccidentExternalRectificationPlan.class);
        util.exportExcel(response, list, "内部事件整改计划数据");
    }

    /**
     * 获取内部事件整改计划详细信息
     */
    @PreAuthorize(hasPermi = "business/accident:plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(accidentExternalRectificationPlanService.selectAccidentExternalRectificationPlanById(id));
    }

    /**
     * 新增内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business/accident:plan:add")
    @Log(title = "内部事件整改计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccidentExternalRectificationPlan accidentExternalRectificationPlan) {
        return toAjax(accidentExternalRectificationPlanService.insertAccidentExternalRectificationPlan(accidentExternalRectificationPlan));
    }

    /**
     * 修改内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business/accident:plan:edit")
    @Log(title = "内部事件整改计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccidentExternalRectificationPlan accidentExternalRectificationPlan) {
        return toAjax(accidentExternalRectificationPlanService.updateAccidentExternalRectificationPlan(accidentExternalRectificationPlan));
    }

    /**
     * 删除内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business/accident:plan:remove")
    @Log(title = "内部事件整改计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accidentExternalRectificationPlanService.deleteAccidentExternalRectificationPlanByIds(ids));
    }
}
